package com.etoak.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class OrderQueueConfig {
    public static final String EXCHANGE = "amqp.order";
    public static final String KEY = "order";
    public static final String QUEUE = "order";
    @Bean
    public CustomExchange orderExchange(){
        Map<String,Object> args = new HashMap<>();
        //使用直接交换机
        args.put("x-delayed-type","direct");
        // 死信交换机
        return new CustomExchange(EXCHANGE,"x-delayed-message",true,false,args);
    }
    @Bean
    public Queue orderQueue(){
        return new Queue(QUEUE);
    }
    @Bean
    public Binding orderBinding(Queue orderQueue,CustomExchange orderExchange){
        return BindingBuilder.bind(orderQueue).to(orderExchange).with(KEY).noargs();
    }
}
